package SQLite3;

import java.io.IOException;
import java.io.InputStream;

class BlobR
        extends InputStream {
    private Blob blob;
    private int pos;

    BlobR(Blob paramBlob) {
        this.blob = paramBlob;
        this.pos = 0;
    }

    public int available()
            throws IOException {
        int i = this.blob.size - this.pos;
        int j = i;
        if (i < 0) {
            j = 0;
        }
        return j;
    }

    public void close()
            throws IOException {
        this.blob.close();
        this.blob = null;
        this.pos = 0;
    }

    public void mark(int paramInt) {
    }

    public boolean markSupported() {
        return false;
    }

    public int read()
            throws IOException {
        byte[] arrayOfByte = new byte[1];
        int i = this.blob.read(arrayOfByte, 0, this.pos, arrayOfByte.length);
        if (i > 0) {
            this.pos += i;
        }
        for (i = arrayOfByte[0]; ; i = -1) {
            return i;
        }
    }

    public int read(byte[] paramArrayOfByte)
            throws IOException {
        int i = this.blob.read(paramArrayOfByte, 0, this.pos, paramArrayOfByte.length);
        if (i > 0) {
            this.pos += i;
        }
        return i;

    }

    public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
            throws IOException {
        int i = paramInt2;
        if (paramInt1 + paramInt2 > paramArrayOfByte.length) {
            i = paramArrayOfByte.length - paramInt1;
        }
        if (i < 0) {
            paramInt1 = -1;
        }
        if (i == 0) {
            paramInt1 = 0;
        } else {
            paramInt1 = this.blob.read(paramArrayOfByte, paramInt1, this.pos, i);
            if (paramInt1 > 0) {
                this.pos += paramInt1;
            } else {
                paramInt1 = -1;
            }
        }
        return paramInt1;
    }

    public void reset()
            throws IOException {
    }

    public long skip(long paramLong)
            throws IOException {
        paramLong = this.pos + paramLong;
        if (paramLong < 0L) {
            paramLong = 0L;
            this.pos = 0;
        }
        if (paramLong > this.blob.size) {
            paramLong = this.blob.size;
            this.pos = this.blob.size;
        } else {
            this.pos = ((int) paramLong);
        }
        return paramLong;
    }
}
